home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Converting Strings to Upper Case
- Date: Mon, 18 Mar 96 16:14:03 GMT
- Organization: none
- Message-ID: <827165643snz@genesis.demon.co.uk>
- References: <4ifra6$52i@scipio.cyberstore.ca> <DoFA24.AL7@iquest.net> <4ii1nh$bng@castle.nando.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4ii1nh$bng@castle.nando.net>
- actuary@nando.net "Bill McCarthy" writes:
-
- >In <DoFA24.AL7@iquest.net>, dlmiller@iquest.net (Doug & Rose Miller) writes:
- >>ejw@news.cyberstore.ca () wrote:
- >>+Hi,
- >>+
- >>+
- >>+and the string would be modified. I just can't seem to wrap my head around
- >>+the best way that I know is better than writing a for loop to check each
- >>+element in the array?
- >>+
- >>+I apologize if this in the FAQ; I am still going thorugh it. Any help
- >>+would be greatly appreciated.
- >>+
- >>+Eric Woodward.
- >>+ejw@cyberstore.ca.
- >>+
- >>
- >>
- >>#include <stdio.h>
- >>
- >>void main (void) {
- >
- >Oh, please! Read the FAQ to avoid posting crap like this.
- >
- >>char test[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ";
- >>char *p;
- >>
- >>printf ("%s\n", &test);
- >
- >&test ??? How about just test?
- >
- >>for (p = test; *p; *p++)
- >
- >And what do you think you are accomplishing with *p++ that p++ or ++p
- >wouldn't do???
- >
- >> if (isalpha(*p)) *p ^= 0x20; /* for ascii machines e.g. PC; use 0x40 for
- > ebcdic machines e.g. IBM mainframe */
-
- You could make the code itself more portable (and IMHO clearer) by writing
- this as:
-
- if (isalpha(*p)) *p ^= 'A' ^ 'a';
-
- This still isn't guaranteed by the C language itself but it works for the
- character sets you are likely to encounter in the "C" locale. Whether such a
- hack is preferable over the 'correct' version below is questionable
- and depends on the use to which it is being applied.
-
- *p = isupper(*p) ? tolower(*p) : toupper(*p);
-
- >isalpha() has not been declared. It takes an int and *p may be a signed
- >char, how about *(unsigned char *)p.
-
- It is certainly tempting to make p unsigned char *.
-
- > Also, your code is toggling between
- >upper and lower case.
-
- To be fair that looked like what was asked:
-
- >>+I need to write a function to convert a string containg upper or lower case
- >>+characters to the opposite case. Something like:
-
- However the declarations suggest otherwise:
-
- >>+ void libConvertUpperCase(char *str); and
- >>+ void libConvertLowerCase(char *str);
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-